package com.donggua.aichebao.login.request;

import android.content.Context;
import android.util.Log;

import com.android.volley.ParseError;
import com.android.volley.http.RequestEntity;
import com.android.volley.http.StringEntity;
import com.android.volley.toolbox.RequestFuture;

import org.json.JSONException;

import com.dg.acb.utils.configdata.XXConstants;
import com.xx.xiawan.net.ErrorCode;
import com.xx.xiawan.net.PostSyncRequest;

/**
 * Created by fzh on 2017/8/4.
 */

public class DGLoginRequest extends PostSyncRequest<DGLoginResponse>{
    public static final String LOGIN_URL = XXConstants.URI_LOGIN;
    public DGLoginRequest(String url, RequestEntity rEntity, RequestFuture<DGLoginResponse> future) {
        super(url, rEntity, future);
    }

    public static DGLoginRequest create(Context context,StringEntity entity){
        RequestFuture<DGLoginResponse> requestFuture = RequestFuture.newFuture();
        Log.e("login"," login url is "+LOGIN_URL);
        return new DGLoginRequest(LOGIN_URL,
                entity, requestFuture);
    }

    @Override
    protected DGLoginResponse handlerResponse(String jsonString) throws ParseError {
        try{
            DGLoginResponse reportResponse = new DGLoginResponse(jsonString);
            return reportResponse;
        }
        catch (JSONException e){
            e.printStackTrace();
        }
        return new DGLoginResponse(ErrorCode.UNKNOWN_ERROR.getCode(),
                ErrorCode.UNKNOWN_ERROR.getMessage(null));
    }
}
